Skip to content

fix(checkout): use available_domains for auto-generated site URLs#1072

Merged
superdav42 merged 3 commits into
mainfrom
fix/site-url-domain-auto-generate
May 2, 2026
Merged

fix(checkout): use available_domains for auto-generated site URLs#1072
superdav42 merged 3 commits into
mainfrom
fix/site-url-domain-auto-generate

Conversation

@superdav42

@superdav42 superdav42 commented May 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

When auto_generate_site_url is enabled on a checkout form, the site URL field previously ignored the available_domains configuration and fell back to $current_site->domain (the network primary domain). This caused domain-mapped checkout sites (e.g. ultimateagentwp.ai) to create subsites under the wrong domain (mygratis.site instead of ultimateagentwp.ai), breaking same-domain SSO and creating a confusing user experience.

Changes

  • Hidden site_domain field: When auto-generate is on and available_domains is configured, a hidden site_domain field is now emitted with the first available domain. The checkout session picks this up via request_or_session('site_domain') and passes it to wu_get_site_domain_and_path().
  • Admin UI: The "Available Domains" textarea is now visible when auto-generate is enabled (was hidden behind !auto_generate_site_url && enable_domain_selection). Updated description to explain the auto-generate behavior.

Testing

Verified end-to-end: checkout on ultimateagentwp.ai → subsite created as username.ultimateagentwp.ai (not username.mygratis.site) → SSO auto-login works → AI agent admin page loads successfully.


aidevops.sh v3.13.95 plugin for OpenCode v1.3.17 with claude-sonnet-4-6 spent 2d 2h and 8 tokens on this as a headless worker.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed domain selection in checkout to properly use the first available domain as the site base, preventing unintended fallback to network primary.
    • Expanded domain configuration field visibility to display in additional setup scenarios.
    • Enhanced field descriptions for improved configuration guidance.

When auto_generate_site_url is enabled, the checkout previously ignored the
available_domains config and fell back to $current_site->domain (the network
primary). This meant domain-mapped checkout sites (e.g. ultimateagentwp.ai)
created subsites under the wrong domain (mygratis.site instead of
ultimateagentwp.ai).

Now when auto-generate is on and available_domains is configured, a hidden
site_domain field is emitted with the first available domain. Also makes the
Available Domains textarea visible in admin when auto-generate is enabled.
@coderabbitai

coderabbitai Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@superdav42 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 14 minutes and 19 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a4b82cf3-d972-484f-8382-c11c2045b677

📥 Commits

Reviewing files that changed from the base of the PR and between 21cdf2f and f7aea7b.

📒 Files selected for processing (1)
  • inc/checkout/signup-fields/class-signup-field-site-url.php
📝 Walkthrough

Walkthrough

This change enhances site domain field configuration during checkout signup. The "Available Domains" field description is expanded, its visibility condition is updated to show when auto-generate is enabled or domain selection is enabled, and domain-parsing logic injects a hidden site_domain field using the first available domain when auto-generation is active.

Changes

Site Domain Field Configuration and Generation

Layer / File(s) Summary
Field Configuration
inc/checkout/signup-fields/class-signup-field-site-url.php (lines 242–252)
The available_domains field description is extended with base-domain usage details. Visibility condition changes from !auto_generate_site_url && enable_domain_selection to auto_generate_site_url || enable_domain_selection.
Domain Injection Logic
inc/checkout/signup-fields/class-signup-field-site-url.php (lines 295–319)
Within the auto_generate_site_url branch of to_fields_array(), when available_domains is provided, the code parses the newline-separated domain list and injects a hidden site_domain field set to the first domain.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A domain tale, quite neat and small,
With hidden fields that answer the call,
Parse and inject with carrots so fine,
The first one chosen, perfectly aligned!
A checkout that knows just where to dwell. 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(checkout): use available_domains for auto-generated site URLs' directly and clearly summarizes the main change—ensuring auto-generated site URLs respect the available_domains configuration.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/site-url-domain-auto-generate

Tip

💬 Introducing Slack Agent: Turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get your free trial and get 200 agent minutes per Slack user (a $50 value).


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 14 minutes and 19 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
inc/checkout/signup-fields/class-signup-field-site-url.php (1)

298-318: 💤 Low value

Implementation looks correct; minor duplication with get_domain_options().

The logic correctly injects a hidden site_domain field when auto-generate is enabled and available domains are configured. The guards for empty values are sound.

Consider extracting the domain parsing logic to reuse with get_domain_options() (lines 422-424), which performs similar parsing but with slightly different ordering:

// Line 309 (new code)
array_filter(array_map('trim', explode(PHP_EOL, $attributes['available_domains'])))

// Lines 422-424 (existing)
$domains = array_filter(explode(PHP_EOL, $domain_options));
$domains = array_map(fn($item) => trim((string) $item), $domains);

Both work correctly, but a shared helper would ensure consistent behavior and reduce duplication.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@inc/checkout/signup-fields/class-signup-field-site-url.php` around lines 298
- 318, Extract the duplicate domain-parsing logic into a single helper (e.g., a
private method parse_domains(string $raw): array) and use it from both the new
site_domain injection code (where $attributes['available_domains'] is parsed and
$checkout_fields['site_domain'] is set) and from get_domain_options(); the
helper should explode by PHP_EOL, trim each item, filter out empties, and return
the resulting array so both places call
parse_domains($attributes['available_domains'] or $domain_options) instead of
doing inline array_map/array_filter.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@inc/checkout/signup-fields/class-signup-field-site-url.php`:
- Around line 298-318: Extract the duplicate domain-parsing logic into a single
helper (e.g., a private method parse_domains(string $raw): array) and use it
from both the new site_domain injection code (where
$attributes['available_domains'] is parsed and $checkout_fields['site_domain']
is set) and from get_domain_options(); the helper should explode by PHP_EOL,
trim each item, filter out empties, and return the resulting array so both
places call parse_domains($attributes['available_domains'] or $domain_options)
instead of doing inline array_map/array_filter.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fd2ca4e9-41bf-467e-be66-3035442ca680

📥 Commits

Reviewing files that changed from the base of the PR and between 331ca55 and 21cdf2f.

📒 Files selected for processing (1)
  • inc/checkout/signup-fields/class-signup-field-site-url.php

@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown

Performance Test Results

Performance test results for 929f933 are in 🛎️!

Note: the numbers in parentheses show the difference to the previous (baseline) test run. Differences below 2% or 0.5 in absolute values are not shown.

URL: /

Run DB Queries Memory Before Template Template WP Total LCP TTFB LCP - TTFB
0 41 37.78 MB 865.50 ms (-28.50 ms / -3% ) 166.00 ms (+6.50 ms / +4% ) 1078.50 ms (-33.00 ms / -3% ) 2004.00 ms (-50.00 ms / -2% ) 1914.30 ms (-46.05 ms / -2% ) 88.50 ms (-2.75 ms / -3% )
1 56 49.10 MB 906.50 ms (-32.50 ms / -4% ) 143.50 ms (-3.50 ms / -2% ) 1048.50 ms (-37.00 ms / -4% ) 2016.00 ms (-62.00 ms / -3% ) 1933.75 ms (-61.85 ms / -3% ) 82.05 ms

…erate mode

When auto_generate_site_url is enabled, only one domain is allowed so
show a single-line text input instead of a textarea. The textarea is
kept for the manual domain-selection mode (multiple domains).

- available_domains: text input, shown when auto-generate is on
- available_domains_multi: textarea, shown when domain selection is on
- Simplified hidden site_domain injection (no more newline splitting)
@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

Comment thread inc/checkout/signup-fields/class-signup-field-site-url.php Outdated
@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@superdav42

Copy link
Copy Markdown
Collaborator Author

DISPATCH_CLAIM nonce=dfa2d5f37937103130eb803b4b69c9e0 runner=superdav42 ts=2026-05-02T23:11:26Z max_age_s=1800 version=3.14.1

@superdav42 superdav42 merged commit 793057d into main May 2, 2026
11 checks passed
@superdav42

Copy link
Copy Markdown
Collaborator Author

Summary

When auto_generate_site_url is enabled on a checkout form, the site URL field previously ignored the available_domains configuration and fell back to $current_site->domain (the network primary domain). This caused domain-mapped checkout sites (e.g. ultimateagentwp.ai) to create subsites under the wrong domain (mygratis.site instead of ultimateagentwp.ai), breaking same-domain SSO and creating a confusing user experience.

Changes

  • Hidden site_domain field: When auto-generate is on and available_domains is configured, a hidden site_domain field is now emitted with the first available domain. The checkout session picks this up via request_or_session('site_domain') and passes it to wu_get_site_domain_and_path().
  • Admin UI: The "Available Domains" textarea is now visible when auto-generate is enabled (was hidden behind !auto_generate_site_url && enable_domain_selection). Updated description to explain the auto-generate behavior.

Testing

Verified end-to-end: checkout on ultimateagentwp.ai → subsite created as username.ultimateagentwp.ai (not username.mygratis.site) → SSO auto-login works → AI agent admin page loads successfully.


aidevops.sh v3.13.95 plugin for OpenCode v1.3.17 with claude-sonnet-4-6 spent 2d 2h and 8 tokens on this as a headless worker.


Merged via PR #1072 to main.
Merged by deterministic merge pass (pulse-wrapper.sh).

superdav42 added a commit that referenced this pull request May 3, 2026
…ion in Signup_Field_Site_Url (#1080)

PR #1072 review feedback: the inline domain-parsing logic in get_domain_options()
(array_filter/array_map/explode) was duplicated. Extract it into a private
parse_domains() method so both the auto-generate path and the domain-selection
path share a single, consistent implementation.

Also removes the blank line before the empty-domain guard (human reviewer suggestion
at PR #1072 line 317).

Resolves #1075
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant